using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// 创建一个菜单项，用于在Unity编辑器中创建这个效果的实例
[CreateAssetMenu(fileName = "Ice And Fire effect", menuName = "Data/Item effect/Ice And Fire")]
public class IceAndFire_Effect : ItemEffect
{
    // 序列化字段，使其在Unity编辑器中可见
    [SerializeField] private GameObject iceAndFirePrefab;
    [SerializeField] private float xVelocity;

    // 重写基类的ExecuteEffect方法
    public override void ExecuteEffect(Transform _respawnPositon)
    {
        // 获取玩家实例
        Player player = PlayerManager.instance.player;

        // 检查是否是第三次攻击
        bool thridAttack = player.primaryAttack.comboCounter == 2;

        // 如果是第三次攻击，生成冰与火效果
        if (thridAttack)
        {
            // 在指定位置生成冰与火效果的实例
            GameObject newIceAndFire = Instantiate(iceAndFirePrefab, _respawnPositon.position, player.transform.rotation);
            // 设置冰与火效果的速度
            newIceAndFire.GetComponent<Rigidbody2D>().velocity = new Vector2(xVelocity * player.facingDir, 0);
            // 10秒后销毁冰与火效果的实例
            Destroy(newIceAndFire, 10);
        }
    }
}